package com.ruoyi.course.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.course.mapper.CdCourseMessageMapper;
import com.ruoyi.course.domain.CdCourseMessage;
import com.ruoyi.course.service.ICdCourseMessageService;

/**
 * 课程信息表Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-17
 */
@Service
public class CdCourseMessageServiceImpl implements ICdCourseMessageService 
{
    @Autowired
    private CdCourseMessageMapper cdCourseMessageMapper;

    /**
     * 查询课程信息表
     * 
     * @param courseId 课程信息表主键
     * @return 课程信息表
     */
    @Override
    public CdCourseMessage selectCdCourseMessageByCourseId(Long courseId)
    {
        return cdCourseMessageMapper.selectCdCourseMessageByCourseId(courseId);
    }

    /**
     * 查询课程信息表列表
     * 
     * @param cdCourseMessage 课程信息表
     * @return 课程信息表
     */
    @Override
    public List<CdCourseMessage> selectCdCourseMessageList(CdCourseMessage cdCourseMessage)
    {
        return cdCourseMessageMapper.selectCdCourseMessageList(cdCourseMessage);
    }

    /**
     * 新增课程信息表
     * 
     * @param cdCourseMessage 课程信息表
     * @return 结果
     */
    @Override
    public int insertCdCourseMessage(CdCourseMessage cdCourseMessage)
    {
        cdCourseMessage.setCourseId(System.currentTimeMillis());
        cdCourseMessage.setCreateBy(SecurityUtils.getUsername());
        cdCourseMessage.setCreateTime(DateUtils.getNowDate());
        return cdCourseMessageMapper.insertCdCourseMessage(cdCourseMessage);
    }

    /**
     * 修改课程信息表
     * 
     * @param cdCourseMessage 课程信息表
     * @return 结果
     */
    @Override
    public int updateCdCourseMessage(CdCourseMessage cdCourseMessage)
    {
        cdCourseMessage.setUpdateBy(SecurityUtils.getUsername());
        cdCourseMessage.setUpdateTime(DateUtils.getNowDate());
        return cdCourseMessageMapper.updateCdCourseMessage(cdCourseMessage);
    }

    /**
     * 批量删除课程信息表
     * 
     * @param courseIds 需要删除的课程信息表主键
     * @return 结果
     */
    @Override
    public int deleteCdCourseMessageByCourseIds(Long[] courseIds)
    {
        return cdCourseMessageMapper.deleteCdCourseMessageByCourseIds(courseIds);
    }

    /**
     * 删除课程信息表信息
     * 
     * @param courseId 课程信息表主键
     * @return 结果
     */
    @Override
    public int deleteCdCourseMessageByCourseId(Long courseId)
    {
        return cdCourseMessageMapper.deleteCdCourseMessageByCourseId(courseId);
    }

    /**
     * 查询由自己负责的课程（负责教师）
     * @return
     */
    @Override
    public List<CdCourseMessage> courseListChargedBySelf() {
        CdCourseMessage cdCourseMessage = new CdCourseMessage();
        cdCourseMessage.setChargeTeacherId(SecurityUtils.getUserId());
        return cdCourseMessageMapper.selectCdCourseMessageList(cdCourseMessage);
    }

    @Override
    public Long selectCdCourseMessageByCourseName(String courseName) {
        return cdCourseMessageMapper.selectCdCourseMessageByCourseName(courseName);
    }
}
